package com.mes.service.lc;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mes.dao.lc.ProductReturnMapper;
import com.mes.entity.lc.MaterialReturn;
import com.mes.entity.lc.ProductGoku;
import com.mes.entity.lc.ProductReturn;
import com.mes.entity.lc.ProductStock;
import com.mes.entity.yzl.ReturnOrder;
import com.mes.entity.yzlExtend.ExtendProContactOrder;

/**
 * 产品退货 service实现类
 * @ClassName:ProductReturnServiceImpl
 * @Description:
 * @Author LC
 * @Date 2018年2月1日下午2:58:42
 * @version 1.0
 */
@Service
public class ProductReturnServiceImpl implements ProductReturnService {
	
	@Autowired
	ProductReturnMapper	productReturnMapper;

	/**
	 * 分页查询
	 * @param productReturn
	 * @return
	 */
	@Override
	public List<ProductReturn> selectfyprc(ProductReturn productReturn) {
		return productReturnMapper.selectfyprc(productReturn);
	}

	/**
	 * 查询总数
	 * @param productReturn
	 * @return
	 */
	@Override
	public int selectfyprccont(ProductReturn productReturn) {
		return productReturnMapper.selectfyprccont(productReturn);
	}

	/**
	 * 查询所有未退货且审批通过的产品退货单
	 * @return
	 */
	@Override
	public List<ReturnOrder> selectprcall() {
		return productReturnMapper.selectprcall();
	}

	/**
	 * 根据产品退货单主键给出对应信息
	 * @param ids
	 * @return
	 */
	@Override
	public List<ExtendProContactOrder> selectpcoall(Long ids) {
		return productReturnMapper.selectpcoall(ids);
	}

	/**
	 * 开始退货
	 */
	@Override
	public int saveprc(ExtendProContactOrder pgk, String suprname,
			String number, String nowtime) {
		//产品退货表
		ProductReturn productReturn = new ProductReturn();
		//产品库存
		ProductStock productStock = new ProductStock();
	    
		//添加产品出库
		productReturn.setRematid(pgk.getProductorId());//产品基础主键
		productReturn.setReodd(number);//退货单号
		productReturn.setRetime(nowtime);//退货时间
		productReturn.setRecustom(suprname);//客户
		productReturn.setRecar(pgk.getProduct().getCartype());//车种
		productReturn.setRenumb(pgk.getProduct().getNum());//品编
		productReturn.setRename(pgk.getProduct().getName());//品名
		productReturn.setRepici(pgk.getBatch());//批次
		productReturn.setRenum(String.valueOf(pgk.getOutQ()));//数量
		productReturn.setRecodee(pgk.getBarcode());//条形码 
		productReturn.setRepeop("管理员");//录入人
		
		//添加产品库存
	    productStock.setSsck("产品");//所属仓库
	    
	    Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("pgk", productReturn);
		paramMap.put("ps", productStock);
		
		return productReturnMapper.saveprc(paramMap);
	}

	/**
	 * 修改销售退货单状态
	 * @param ids
	 */
	@Override
	public void updatereturnorder(Long ids) {
		 productReturnMapper.updatereturnorder(ids);
	}
	
}	
